package com.gt.xmall.web;

import java.util.List;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.gt.xmall.model.GtdContext;
import com.gt.xmall.service.GtdContextService;
import com.gt.xmall.web.BaseController;

import com.gt.xmall.model.GtdTopic;
import com.gt.xmall.service.GtdTopicService;

@Controller
@RequestMapping(value = "/gtd/gtdtopic/")
public class GtdTopicController extends BaseController {
	
	@Autowired
	private GtdTopicService gtdTopicService;
	
	@RequestMapping(value = "list",method = RequestMethod.GET)
	public String list(Model model){
		List<GtdTopic> list = gtdTopicService.getGtdTopics();
		model.addAttribute("gtdTopicList", list);
		return "gtd/gtdTopicList";
	}
	@RequestMapping(value = "show/{id}",method = RequestMethod.GET)
	public String show(@PathVariable("id") String id,Model model){
		GtdTopic gtdTopic =gtdTopicService.getGtdTopic(new Long(id));
		model.addAttribute("gtdTopic", gtdTopic);
		return "gtd/gtdTopicForm";
		
	}
	@RequestMapping(value="save",method = RequestMethod.POST)
	public String save(@Valid GtdTopic gtdTopic,RedirectAttributes redirectAttributes){
		gtdTopic = gtdTopicService.saveGtdTopic(gtdTopic);
//		redirectAttributes.addAttribute("gtdContext", gtdContext);
		return "redirect:/gtd/gtdtopic/show/"+gtdTopic.getId();
	} 
	@RequestMapping(value = "new",method = RequestMethod.GET)
	public String blankForm(){
		return "gtd/gtdTopicForm";
	}
	
	@RequestMapping(value = "delete/{id}",method = RequestMethod.GET)
	public String delete(@PathVariable("id") String id,Model model){
		gtdTopicService.deleteGtdTopic(new Long(id));
		
		return "redirect:/gtd/gtdtopic/list";
		
	}
	
}